/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/length-of-last-word
   @Language: C++
   @Datetime: 19-07-01 10:06
   */

class Solution {
public:
	int lengthOfLastWord(string &s) {
		for(int i=s.length(); i-- && s[i]==' '; s.pop_back());
		auto space=s.find_last_of(' ');
		return space==s.npos?s.length():s.length()-space-1;
	}
};
